from django.db import models

#L.Le 25-Oct-2011
# class Addresses (models.Model):
# 	line_1 = models.CharField(max_length=50)
# 	line_2 = models.CharField(max_length=50)
# 	city = models.CharField(max_length=32)
# 	postcode = models.CharField(max_length=10)
# 	country = models.CharField(max_length=32)


class Customer (models.Model):
	GENDER_CHOICES = (
        (u'M', u'Male'),
        (u'F', u'Female'),
   	)
	customer_name = models.CharField(max_length=32)
	customer_gender = models.CharField(max_length=2, choices=GENDER_CHOICES)
	def __unicode__(self):
        	return self.customer_name

class Member(Customer):
	member_phone = models.CharField(max_length=12)
	member_address = models.CharField(max_length=50)
	member_email = models.CharField(max_length=32)
	member_join_date = models.DateField()
	member_other_detail = models.CharField(max_length=100)
	
class Guest(Customer):
	guest_subscription_email = models.CharField(max_length=32)
	
class Supplier (models.Model):
	supplier_address = models.CharField(max_length=50)
	supplier_name = models.CharField(max_length=32)
	supplier_phone = models.CharField(max_length=12)
	supplier_email = models.CharField(max_length=32)
	supplier_other_detail = models.CharField(max_length=100)
	def __unicode__(self):
        	return self.supplier_name

# class ProductType (models.Model):
# 	type_description = models.CharField(max_length=200)
	
class Product (models.Model):
#	product_type = models.ForeignKey(ProductType)
	PRODUCT_TYPES = (
		(u'Fo', u'Food'),
		(u'Fu', u'Furniture'),
		(u'El', u'Electronic'),
		(u'Ot', u'Other')
	)
	supplier = models.ForeignKey(Supplier)
	product_name = models.CharField(max_length=32)
	product_type = models.CharField(max_length=3, choices=PRODUCT_TYPES)
	product_price = models.FloatField();
	product_description = models.CharField(max_length=100)
	def __unicode__(self):
        	return self.product_name
	
class PromotionProduct (models.Model):
	product = models.OneToOneField(Product)
	promotion_rate = models.FloatField()
	def __unicode__(self):
        	return u"%s:%s%%" % (self.product,self.promotion_rate)
	
class Inventory (models.Model):
	product = models.OneToOneField(Product)
	inv_product_quantity = models.IntegerField()
	def __unicode__(self):
		return u"%s:%s" % (self.product.product_name,self.inv_product_quantity)
     

class Order (models.Model):
	ORDER_STATUSES = (
		(u'P', u'Pending'),
		(u'D', u'Delivered'),
		(u'R', u'Returned')
	)
	customer = models.ForeignKey(Customer)
	order_status = models.CharField(max_length=2, choices=ORDER_STATUSES)
	order_date = models.DateField()
	order_deliver_address = models.CharField(max_length=50)
	order_detail = models.CharField(max_length=200)
	product = models.ManyToManyField(Product, through='OrderedItem')
	def __unicode__(self):
        	return u"[%s] - Date:%s - %s" % (self.order_status, self.order_date, self.customer)

class OrderedItem (models.Model):
    order = models.ForeignKey(Order)
    product = models.ForeignKey(Product)
    quantity = models.IntegerField()
    def __unicode__(self):
        	return u"Product: %s - Quantity: %s" % (self.product.product_name,self.quantity)


class Employee (models.Model):
	employee_address = models.CharField(max_length=50)
	employee_name = models.CharField(max_length=32)
	employee_phone = models.CharField(max_length=12)
	employee_email = models.CharField(max_length=32)
	employee_other_detail = models.CharField(max_length=100)
	def __unicode__(self):
        	return self.employee_name
	
class Manager(Employee):
	year_of_experience = models.FloatField();
	def __unicode__(self):
        	return u"%s" % self.employee_name
	
class Clerk(Employee):
	manager = models.ForeignKey(Manager);
	EMPLOYMENT_TYPES =(
		(u'F', u'Full Time'),
		(u'P', u'Part Time'),
	)
	clerk_employment_type = models.CharField(max_length=2, choices=EMPLOYMENT_TYPES)
	clerk_description = models.CharField(max_length=100)
	def __unicode__(self):
        	return self.employee_name

class ServedBy(models.Model):
	customer = models.OneToOneField(Customer)
	clerk = models.ForeignKey(Clerk)
	served_time = models.DateField()
	def __unicode__(self):
        	return u"Customer:%s - Clerk:%s" %(self.customer, self.clerk)
